home *** CD-ROM | disk | FTP | other *** search
- /*
- // common.cc -- $@6&DL$J;q8;(J
- //
- // created in 2/14/1994
- */
-
- #include <ctype.h>
- #include "defs.h"
-
- int16 *Screen = NULL;
- int32 Width, Height, Size;
- FILE *fp;
- jmp_buf ErrorEntry;
- char *Program, *File;
- unsigned char *BitBuffer;
- uint32 BitCache;
- int BitLength;
- int BitBufferLength;
- unsigned char BitField[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 };
- int MaxColorGuaranteed;
- int16 Red[256 + 4], Green[256 + 4], Blue[256 + 4], Palette[256 + 4];
- char *Extension[NumberofFormats];
- char *Format[NumberofFormats];
-
- void Initialize()
- {
- Extension[UNKNOWN] = NULL;
- Extension[ALPHA] = "alp";
- Extension[BETA] = "bet";
- Extension[GAMMA] = "gam";
- Extension[DELTA] = "dlt";
- Extension[PIC] = "pic";
- Extension[MAG] = "mag";
- Extension[MAKI] = "mki";
- Extension[PI] = "pi";
- Extension[ML1] = "ml1";
- Extension[PPM] = "ppm";
- Extension[PBM] = "pbm";
- Format[UNKNOWN] = NULL;
- Format[ALPHA] = "alpha";
- Format[BETA] = "beta";
- Format[GAMMA] = "gamma";
- Format[DELTA] = "delta";
- Format[PIC] = "pic";
- Format[MAG] = "mag";
- Format[MAKI] = "maki";
- Format[PI] = "pi";
- Format[ML1] = "ml1";
- Format[PPM] = "ppm";
- Format[PBM] = "pbm";
- }
-
- void BitBufferLoad()
- {
- fread( BitBuffer, 1, BitBufferSize, fp );
- BitBufferLength = 0;
- }
-
- void BitBufferFlush()
- {
- fwrite( BitBuffer, 1, BitBufferLength, fp );
- BitBufferLength = 0;
- }
-
- void BitBufferLastFlush()
- {
- if ( BitLength != 0 ) {
- BitCache <<= 32 - BitLength;
- BitBuffer[BitBufferLength++] = BitCache & 0xff;
- BitBuffer[BitBufferLength++] = (BitCache >> 8) & 0xff;
- BitBuffer[BitBufferLength++] = (BitCache >> 16) & 0xff;
- BitBuffer[BitBufferLength++] = (BitCache >> 24) & 0xff;
- }
- fwrite( BitBuffer, 1, BitBufferLength, fp );
- }
-
- int istrcmp( char *s1, char *s2 )
- {
- int c1, c2;
-
- if ( *s1 == '\0' && *s2 == '\0' )
- return 0;
- if ( *s1 == '\0' || *s2 == '\0' )
- return 1;
- c1 = isupper (*s1)? tolower (*s1) : *s1;
- c2 = isupper (*s2)? tolower (*s2) : *s2;
- if ( c1 != c2 )
- return 1;
- return istrcmp( s1 + 1, s2 + 1 );
- }
-
- int InferFormat( char *File )
- {
- int Length = strlen (File);
- int i;
-
- if ( Length < 4 )
- return UNKNOWN;
- for ( i = 1; i < NumberofFormats; i++ ) {
- if ( i == PI && istrcmp( Extension[i], File + Length - 2 ) == 0 )
- return PI;
- if ( i != PI && istrcmp( Extension[i], File + Length - 3 ) == 0 )
- return i;
- }
- return UNKNOWN;
- }
-